package com.example.sonone.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class TestController {

    private static final Logger LOGGER = LoggerFactory.getLogger(TestController.class);

    /**
     * 表单方式
     */
    @PostMapping("test")
    public Map<String, Object> test(@RequestParam Map<String, Object> map) {
        System.out.println(map);
        return map;
    }

    /**
     * map里面包list
     * {
     * "name": "123",
     * "id": "223",
     * "params":[
     * {
     * 1"name": "123",
     * "id": "223"
     * },
     * {
     * "name": "44",
     * "id": "4444444444"
     * }
     * ]
     * }
     */
    @PostMapping("test2")
    public Map<String, Object> test2(@RequestBody Map<String, Object> map) {
        System.out.println(map);
        List<Map<String, Object>> list = (List<Map<String, Object>>) map.get("params");
        System.out.println(list);
        return map;
    }

    // json   [ "1","2"]
    @PostMapping("testlist")
    public List testlist(@RequestBody List<String> list) {
        System.out.println(list);
        return list;
    }


    /**
     * list里面包map
     * [
     * {
     * "id":"123",
     * "name":"shengming"
     * },
     * {
     * "id":"123",
     * "name":"shengming"
     * }
     * ]
     */
    @PostMapping("listMap")
    public List listMap(@RequestBody List<Map<String, Object>> list) {
        System.out.println(list);
        return list;
    }

    /**
     * list里面包对象，参数名要和对象一样，不然会bull
     * <p>
     * [
     * {
     * "id":"123",
     * "name":"222"
     * },
     * {
     * "id":"333",
     * "name":"222"
     * }
     * ]
     */
    @PostMapping("listObj")
    public List listObj(@RequestBody List<User> list) {
        System.out.println(list);
        return list;
    }

    /**
     * 127.0.0.1:8080/get1?name=zhangsan&id=123
     */
    @GetMapping("get1")
    public String ge1(String name, String id) {
        System.out.println(name);
        System.out.println(id);
        return "get1";
    }

    /**
     * 127.0.0.1:8080/geVarible/zhangsan121/12121
     */
    @GetMapping("geVarible/{name}/{id}")
    public String geVarible(@PathVariable("name") String name, @PathVariable("id") String id) {
        System.out.println(name);
        System.out.println(id);
        return "geVarible";
    }

    @PostMapping("test3333")
    public void test3333(int id, String name, String sex, String appId) {
        System.out.println(123);
    }


}
